/**
 *  JSimProd - Java simulation code for production processes
 *  Copyleft Jorge Mira Yagüe <jorge.mira.yague@gmail.com>
 *  Universidad de Alicante 2009
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * FrmInterval.java
 *
 * Created on 14-ago-2009, 18:18:48
 */
package gui.forms;

import gui.tools.Receiver;
import java.awt.Image;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import lib.model.Interval;
import lib.model.Period;
import lib.model.PeriodicInterval;

/**
 *
 * @author jorge
 */
public class FrmInterval extends javax.swing.JDialog {

    private Receiver parent;

    /** Creates new form FrmInterval */
    public FrmInterval(Receiver parent) {
        initComponents();
        initDates();

        this.getRootPane().setDefaultButton(btnSave);

        String fileString = "/res/icons/logo.png";
        try {
            Image icon = ImageIO.read(getClass().getResource(fileString));
            this.setIconImage(icon);
        } catch (java.io.IOException ioe) {
            System.out.println("Error loading file: " + fileString);
        }
        this.parent = parent;
        this.setTitle("New interval:");
    }

    private void initDates() {
        for (int i = 1; i <= 12; i++) {
            cbStartMonth.addItem(i);
            cbEndMonth.addItem(i);
            cbFromMonth.addItem(i);
            cbToMonth.addItem(i);

        }
        for (int i = 1; i <= 31; i++) {
            cbStartDay.addItem(i);
            cbEndDay.addItem(i);
            cbFromDay.addItem(i);
            cbToDay.addItem(i);

        }
        for (int i = 2008; i <= 2020; i++) {
            cbStartYear.addItem(i);
            cbEndYear.addItem(i);
            cbFromYear.addItem(i);
            cbToYear.addItem(i);

        }
        for (Period p : Period.values()) {
            cbPeriod.addItem(p);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cbToDay = new javax.swing.JComboBox();
        cbToMonth = new javax.swing.JComboBox();
        cbFromMonth = new javax.swing.JComboBox();
        cbFromDay = new javax.swing.JComboBox();
        cbFromYear = new javax.swing.JComboBox();
        cbToYear = new javax.swing.JComboBox();
        txtFromHour = new javax.swing.JTextField();
        txtToHour = new javax.swing.JTextField();
        lblFrom = new javax.swing.JLabel();
        txtToMinute = new javax.swing.JTextField();
        lblTo = new javax.swing.JLabel();
        txtFromMinute = new javax.swing.JTextField();
        lblColonFrom = new javax.swing.JLabel();
        lblColonTo = new javax.swing.JLabel();
        cbEndDay = new javax.swing.JComboBox();
        cbEndMonth = new javax.swing.JComboBox();
        cbStartMonth = new javax.swing.JComboBox();
        cbStartDay = new javax.swing.JComboBox();
        cbStartYear = new javax.swing.JComboBox();
        cbEndYear = new javax.swing.JComboBox();
        txtStartHour = new javax.swing.JTextField();
        txtEndHour = new javax.swing.JTextField();
        lblStart = new javax.swing.JLabel();
        txtEndMinute = new javax.swing.JTextField();
        lblEnd = new javax.swing.JLabel();
        txtStartMinute = new javax.swing.JTextField();
        lblColonStart = new javax.swing.JLabel();
        lblSEndColon = new javax.swing.JLabel();
        cbPeriod = new javax.swing.JComboBox();
        lblPeriod = new javax.swing.JLabel();
        btnSave = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();

        setModal(true);
        setResizable(false);

        cbToDay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbToDayActionPerformed(evt);
            }
        });

        cbToYear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbToYearActionPerformed(evt);
            }
        });

        txtFromHour.setText("00");

        txtToHour.setText("00");

        lblFrom.setText("From:");

        txtToMinute.setText("00");

        lblTo.setText("To:");

        txtFromMinute.setText("00");

        lblColonFrom.setText(":");

        lblColonTo.setText(":");

        cbEndDay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbEndDayActionPerformed(evt);
            }
        });

        cbEndYear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbEndYearActionPerformed(evt);
            }
        });

        txtStartHour.setText("00");

        txtEndHour.setText("00");

        lblStart.setText("Start:");

        txtEndMinute.setText("00");

        lblEnd.setText("End:");

        txtStartMinute.setText("00");

        lblColonStart.setText(":");

        lblSEndColon.setText(":");

        cbPeriod.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbPeriodActionPerformed(evt);
            }
        });

        lblPeriod.setText("Period:");

        btnSave.setText("Save");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblStart)
                            .addComponent(lblEnd)
                            .addComponent(lblPeriod)
                            .addComponent(lblFrom)
                            .addComponent(lblTo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cbStartMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbStartDay, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbStartYear, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cbEndMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbEndDay, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbEndYear, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(cbPeriod, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cbFromMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbFromDay, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbFromYear, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cbToMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbToDay, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cbToYear, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtEndHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblSEndColon, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(txtStartHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblColonStart)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtStartMinute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtEndMinute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(txtToHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblColonTo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(txtFromHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblColonFrom)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtToMinute)
                                    .addComponent(txtFromMinute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnCancel)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbStartMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbStartDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtStartHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblColonStart)
                    .addComponent(cbStartYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtStartMinute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblStart))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbEndMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbEndDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbEndYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtEndHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblSEndColon)
                    .addComponent(txtEndMinute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEnd))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbPeriod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPeriod))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbFromMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbFromDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbFromYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtFromHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblColonFrom)
                    .addComponent(txtFromMinute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFrom))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbToMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbToDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbToYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtToHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblColonTo)
                    .addComponent(txtToMinute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblTo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancel)
                    .addComponent(btnSave))
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-344)/2, (screenSize.height-258)/2, 344, 258);
    }// </editor-fold>//GEN-END:initComponents

    private void cbToDayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbToDayActionPerformed
}//GEN-LAST:event_cbToDayActionPerformed

    private void cbToYearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbToYearActionPerformed
}//GEN-LAST:event_cbToYearActionPerformed

    private void cbEndDayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEndDayActionPerformed
    }//GEN-LAST:event_cbEndDayActionPerformed

    private void cbEndYearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEndYearActionPerformed
    }//GEN-LAST:event_cbEndYearActionPerformed

    private void cbPeriodActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPeriodActionPerformed
        boolean pNone = (Period) cbPeriod.getSelectedItem() != Period.NONE;
        lblFrom.setEnabled(pNone);
        txtFromHour.setEnabled(pNone);
        txtFromMinute.setEnabled(pNone);
        lblTo.setEnabled(pNone);
        txtToHour.setEnabled(pNone);
        txtToMinute.setEnabled(pNone);
        cbFromDay.setEnabled(pNone);
        cbFromMonth.setEnabled(pNone);
        cbFromYear.setEnabled(pNone);
        cbToDay.setEnabled(pNone);
        cbToMonth.setEnabled(pNone);
        cbToYear.setEnabled(pNone);

    }//GEN-LAST:event_cbPeriodActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        try {

            DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy-HH:mm");
            Date date;
            String string;

            //Start date
            string = cbStartMonth.getSelectedItem().toString() + "/" +
                    cbStartDay.getSelectedItem().toString() + "/" +
                    cbStartYear.getSelectedItem().toString() + "-" +
                    txtStartHour.getText() + ":" +
                    txtStartMinute.getText();
            date = (Date) formatter.parse(string);
            Calendar start = Calendar.getInstance();
            start.setTime(date);

            //End date
            string = cbEndMonth.getSelectedItem().toString() + "/" +
                    cbEndDay.getSelectedItem().toString() + "/" +
                    cbEndYear.getSelectedItem().toString() + "-" +
                    txtEndHour.getText() + ":" +
                    txtEndMinute.getText();
            date = (Date) formatter.parse(string);
            Calendar end = Calendar.getInstance();
            end.setTime(date);

            Interval inter = new Interval(start, end);
            if (Period.valueOf(cbPeriod.getSelectedItem().toString()) == Period.NONE) {
                PeriodicInterval result = new PeriodicInterval(inter,
                        null,
                        Period.NONE);
                parent.reciveObject(result);
            } else {
                //From date
                string = cbFromMonth.getSelectedItem().toString() + "/" +
                        cbFromDay.getSelectedItem().toString() + "/" +
                        cbFromYear.getSelectedItem().toString() + "-" +
                        txtFromHour.getText() + ":" +
                        txtFromMinute.getText();
                date = (Date) formatter.parse(string);
                Calendar from = Calendar.getInstance();
                from.setTime(date);

                //To date
                string = cbToMonth.getSelectedItem().toString() + "/" +
                        cbToDay.getSelectedItem().toString() + "/" +
                        cbToYear.getSelectedItem().toString() + "-" +
                        txtToHour.getText() + ":" +
                        txtToMinute.getText();
                date = (Date) formatter.parse(string);
                Calendar to = Calendar.getInstance();
                to.setTime(date);
                Interval validDates = new Interval(start, end);
                PeriodicInterval result = new PeriodicInterval(inter,
                        validDates,
                        Period.valueOf(cbPeriod.getSelectedItem().toString()));
                parent.reciveObject(result);
            }

            this.setVisible(false);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(rootPane,
                    e.getMessage(),
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_btnSaveActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        this.setVisible(false);
}//GEN-LAST:event_btnCancelActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnSave;
    private javax.swing.JComboBox cbEndDay;
    private javax.swing.JComboBox cbEndMonth;
    private javax.swing.JComboBox cbEndYear;
    private javax.swing.JComboBox cbFromDay;
    private javax.swing.JComboBox cbFromMonth;
    private javax.swing.JComboBox cbFromYear;
    private javax.swing.JComboBox cbPeriod;
    private javax.swing.JComboBox cbStartDay;
    private javax.swing.JComboBox cbStartMonth;
    private javax.swing.JComboBox cbStartYear;
    private javax.swing.JComboBox cbToDay;
    private javax.swing.JComboBox cbToMonth;
    private javax.swing.JComboBox cbToYear;
    private javax.swing.JLabel lblColonFrom;
    private javax.swing.JLabel lblColonStart;
    private javax.swing.JLabel lblColonTo;
    private javax.swing.JLabel lblEnd;
    private javax.swing.JLabel lblFrom;
    private javax.swing.JLabel lblPeriod;
    private javax.swing.JLabel lblSEndColon;
    private javax.swing.JLabel lblStart;
    private javax.swing.JLabel lblTo;
    private javax.swing.JTextField txtEndHour;
    private javax.swing.JTextField txtEndMinute;
    private javax.swing.JTextField txtFromHour;
    private javax.swing.JTextField txtFromMinute;
    private javax.swing.JTextField txtStartHour;
    private javax.swing.JTextField txtStartMinute;
    private javax.swing.JTextField txtToHour;
    private javax.swing.JTextField txtToMinute;
    // End of variables declaration//GEN-END:variables
}
